package service;

import Dao.TeacherDao;
import domain.Teacher;

public class TeacherService {

    TeacherDao teacherDao = new TeacherDao();

    public boolean add(Teacher t) {

        return teacherDao.add(t);
    }

    public boolean isExists(String id) {

        Teacher[] teachers = teacherDao.findAll();
        boolean exists = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher != null && teacher.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public Teacher[] findAll() {

        Teacher[] teachers = teacherDao.findAll();
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher != null) {
                flag = true;
                break;
            }
        }
        if (flag) {
            return teachers;//若为真，表示有数据返回数组地址
        } else {
            return null;
        }
    }

    public void delete(String delId) {
        teacherDao.delete(delId);
    }

    public void update(String updeId, Teacher newT) {
        teacherDao.update(updeId, newT);
    }
}
